/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package edu.chalmers.AV_2DPlatformerFramework.Model;

import java.util.Comparator;

/**
 * Simply compares the strata values of two GameObjects. Lower strata first. Used by GameMap.
 * @version 1.0
 * @author Richard Sundqvist
 * @revised Richard Sundqvist Added javadoc entries.
 */
public class StrataComparator implements Comparator{

    /**
     * Compare to GameObject's strata. Lower strata is considered bigger.
     * @param o1 The first object to compare.
     * @param o2 The second object to compare.
     * @return 0 if equal, 1 if go1 has lower strata. Otherwise -1.
     */
    @Override
    public int compare(Object o1, Object o2) {
        if (!(o1 instanceof GameObject && o2 instanceof GameObject)){
            throw new IllegalArgumentException("StrataComparator handles GameObjects only!");
        }
        GameObject go1 = (GameObject) o1;
        GameObject go2 = (GameObject) o2;
        
        if (go1.getStrata() > go2.getStrata()){
            return -1;
        } else if (go1.getStrata() < go2.getStrata()){
            return 1;
        } else {
            return 0;
        }
    }
}
